import { request, config } from 'utils'
import * as commonService from 'utils/services'

const { api } = config
const { userTenant, userSelection } = api

export async function query(params = {}) {
  params.apiBaseUrl = `${userTenant}`;
  return commonService.commonQuery(params);
}
export async function enable(params = {}) {
  const url = `${userTenant}/${params.id}/enable`;
  return request({ url: url, method: 'GET', data: {} })
}
export async function disable(params = {}) {
  const url = `${userTenant}/${params.id}/disable`;
  return request({ url: url, method: 'GET', data: {} })
}
export async function syncUser(params = {}) {
  const url = `${userTenant}/syncUser`;
  return request({ url: url, method: 'POST', data: params })
}
export async function addUser(params = {}) {
  const url = `${userTenant}/add`;
  return request({
    url: url, method: 'POST', data: {
      phone: params.phone
    }
  })
}

/**
 * 根据userIds获取用户的详细信息
 * @param {*} userIds
 */
export async function listByUserIds(userIds) {
  const url = `${userTenant}/listByUserIds`;
  return request({ url: url, method: 'POST', data: userIds })
}
/**
 * 分组根据userIds获取绑定用户
 * @param {*} userIds
 */
export async function listGroupByUserIds(params) {
  const url = `${userTenant}/listGroupByUserIds`;
  return request({ url: url, method: 'POST', data: params })
}

/**
 * 选择销售员
 */
export async function selectSalesmen() {
  const url = `${userSelection}/salesmen`;
  return request({ url: url, method: 'GET' })
}

/**
 * 通过门店出销售员列表
 * @param id
 * @returns {Promise<*>}
 */
export async function byDistributor(id) {
  const url = `${userSelection}/salesmen/byDistributor/${id}`;
  return request({ url: url, method: 'GET' })
}

export async function queryUserByKeywords(keyword) {
  const url = `${userTenant}/queryUserByKeywords?keywords=${keyword}`;
  return request({ url: url, method: 'PUT'})
}
